home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1999 March
/
EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso
/
earcd
/
-archivi
/
-recent2
/
amhelios.lha
/
AmHelios
/
test_3.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-13
|
5KB
|
171 lines
////////////////////////////////////////////////////////////
//
// TEST_3.CPP - Cubic Tetrahedron Test Program
//
// Version: 1.03A
//
// History: 94/08/23 - Version 1.00A release.
// 94/12/16 - Version 1.01A release.
// 95/02/05 - Version 1.02A release.
// 95/07/21 - Version 1.02B release.
// 96/02/14 - Version 1.02C release.
// 96/04/01 - Version 1.03A release.
//
// Compilers: Microsoft Visual C/C++ Professional V1.5
// Borland C++ Version 4.5
//
// Author: Ian Ashdown, P.Eng.
// byHeart Software Limited
// 620 Ballantree Road
// West Vancouver, B.C.
// Canada V7S 1W3
// Tel. (604) 922-6148
// Fax. (604) 987-7621
//
// Copyright 1994-1996 byHeart Software Limited
//
// The following source code has been derived from:
//
// Ashdown, I. 1994. Radiosity: A Programmer's
// Perspective. New York, NY: John Wiley & Sons.
//
// It may be freely copied, redistributed, and/or modified
// for personal use ONLY, as long as the copyright notice
// is included with all source code files.
//
////////////////////////////////////////////////////////////
// NOTE: _NOT_WIN_APP must be globally defined for this
// program to be successfully compiled
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>
#include <time.h>
#include "error.h"
#include "parse.h"
#include "cubic_t.h"
// Default entity directory path
static char NoEntityDir[] = "";
static CubicTetra Cubic; // Cubic tetrahedron
static Parse Parser; // World file parser
static Environ Environment; // Environment
double Calculate( float *, WORD, BOOL );
int main( int argc, char **argv )
{
char *pentdir; // Entity directory path
float *ff_array; // Form factor array
WORD num_elem; // Number of elements
// Check cubic tetrahedron status
if (Cubic.GetStatus() != TRUE)
{
OutOfMemory();
return 1;
}
// Get entity directory path (if any)
if (argc > 2)
pentdir = argv[2];
else
pentdir = NoEntityDir;
// Parse the environment file
if (Parser.ParseFile(argv[1], pentdir, &Environment) ==
FALSE)
return 1;
// Allocate form factor array
num_elem = Environment.GetNumElem();
if ((ff_array = new float[num_elem]) == NULL)
{
OutOfMemory();
return 1;
}
// Seed the random number generator
srand((unsigned) time(NULL));
// Calculate and display form factors
// (void) Calculate(ff_array, num_elem, TRUE);
// Recalculate form factors and display execution time
cout << endl << "Resolution = " << FF_ArrayRes << " x "
<< FF_ArrayRes << " cells" << endl;
cout << "Execution time = "<< Calculate(ff_array,
num_elem, FALSE) << " seconds";
delete [] ff_array; // Delete form factor array
return 0;
}
// Calculate form factors
double Calculate( float *ff_array, WORD num_elem, BOOL
ff_flag )
{
clock_t start, end; // Execution time variables
Instance *penv; // Environment pointer
Instance *pinst; // Instance pointer
Surface3 *psurf; // Surface pointer
Patch3 *ppatch; // Patch pointer
WORD src_id = 1; // Source polygon identifier
WORD rcv_id; // Receiving polygon identifier
// Get environment pointer
pinst = penv = Environment.GetInstPtr();
if (ff_flag == FALSE)
{
start = clock(); // Start the program timer
}
// Walk the instance list
while (pinst != NULL)
{
// Walk the surface list
psurf = pinst->GetSurfPtr();
while (psurf != NULL)
{
// Walk the patch list
ppatch = psurf->GetPatchPtr();
while (ppatch != NULL)
{
// Calculate patch to element form factors
Cubic.CalcFormFactors(ppatch, penv, ff_array,
num_elem);
if (ff_flag == TRUE)
{
// Report form factors
cout << "Patch " << src_id << endl;
for (rcv_id = 0; rcv_id < num_elem; rcv_id++)
cout << " FF(" << src_id << "," << (rcv_id + 1)
<< ") = " << ff_array[rcv_id] << endl;
}
src_id++;
cout << src_id << endl;
ppatch = ppatch->GetNext();
}
psurf = psurf->GetNext();
}
pinst = pinst->GetNext();
}
if (ff_flag == FALSE)
{
end = clock(); // Stop the program timer
// Return form factor calculation time
return (double) (end - start) / CLOCKS_PER_SEC;
}
else
return 0.0;
}